home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / gethostnam < prev    next >
Text File  |  1996-11-09  |  2KB  |  73 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/gethostnam,v $
  4.  * $Date: 1996/10/30 21:59:01 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: gethostnam,v $
  10.  * Revision 1.2  1996/10/30 21:59:01  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:35:27  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: gethostnam,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
  19.  
  20. #include <string.h>
  21. #include <errno.h>
  22. #include <unistd.h>
  23. #include <sys/os.h>
  24.  
  25. /* gethostname() returns "acorn<station>" */
  26.  
  27. int
  28. gethostname (char *name, size_t len)
  29. {
  30.   int r[3];
  31.   _kernel_oserror *e;
  32.   static char buf[8];
  33.   static char hex[16] =
  34.   {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  35.    'A', 'B', 'C', 'D', 'E', 'F'};
  36.  
  37.   /* Create a string that consists of "acorn<econet station number>".  */
  38.   strcpy (buf, "acorn");
  39.   if (e = os_byte (0xa1, 0, 0, r))
  40.     {
  41.       __seterr (e);
  42.       return -1;
  43.     }
  44.   buf[7] = 0;
  45.   buf[6] = hex[r[1] & 0xf];
  46.   buf[5] = hex[(r[1] >> 4) & 0xf];
  47.  
  48.   if (strlen (buf) <= len)
  49.     {
  50.       strcpy (name, buf);
  51.       return 0;
  52.     }
  53.  
  54.   errno = ENAMETOOLONG;
  55.   strncpy (name, buf, len);
  56.   buf[len] = '\0';
  57.   return -1;
  58. }
  59.  
  60. /* Set the name of the host machine.  */
  61.  
  62. int
  63. sethostname (const char *name, size_t length)
  64. {
  65.   /* Bit of a difficult one to set under RISC OS. Set errno
  66.      and return -1 which indicates that the calling process
  67.      is not privileged enough to set the host name.  */
  68.   name = name;
  69.   length = length;
  70.   errno = EPERM;
  71.   return -1;
  72. }
  73.